package com.tedu.controller;


import com.alibaba.fastjson.JSON;
import com.tedu.pojo.Address;
import com.tedu.pojo.ResultData;

import org.springframework.ui.Model;
import com.tedu.pojo.User;
import com.tedu.servies.AddressServies;
import com.tedu.servies.UserServies;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;


@Controller
public class AddressController {
    @Autowired
    AddressServies addressServies;
    UserServies userServies;


    @RequestMapping("/user/Address")
    public String myOrder() { return "addressAdmin";
    }


    @RequestMapping("/user/Addressupdate")
//    @ResponseBody
    public String toUpdateUser(Model model, Address address, HttpSession session) {
        System.out.println("你正在进入信息修改页面");
        User user = (User) session.getAttribute("user");
        int id = user.getId();
        address.setUserId(id);
        List<Address> addressesto = addressServies.getid(address.getUserId());
        model.addAttribute("list",addressesto);
        System.out.println(addressesto);

        return "addressAdmin";
    }


    @RequestMapping("/user/updateadd")
    public String updateadd(Model model,Address address,HttpSession session){
        User user = (User) session.getAttribute("user");
        int id = user.getId();
        address.setUserId(id);
        ResultData resultDataadd;
        int update = addressServies.updateaddress(address);
        if (update>0){
            System.out.println("更该成功");
            resultDataadd = new ResultData("更该成功",200,null);
            System.out.println(address);
        }
        else {
            System.out.println("更改失败");
            resultDataadd = new ResultData("更该失败",0,null);
        }
        System.out.println(resultDataadd);
        String string = JSON.toJSONString(resultDataadd);
        return "string";
    }


}
